package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/*护理项目相关的接口*/
@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理工程相关的接口")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

// 1.1 护理项目 分页查询接口;四个参数：项目名称，状态，页码，每页大小
    @GetMapping
    @ApiOperation("分页条件查询护理项目")
    public ResponseResult selectByPage
    (@ApiParam(value = "护理项目名称") String name, Integer status, Integer pageNum, Integer pageSize){
        PageResponse<NursingProjectVo> NursingProjectVoPageResponse = nursingProjectService.selectByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(NursingProjectVoPageResponse);
    }

//1.2 新增项目
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }
    // 1.3 根据id查询项目
   @GetMapping("/{id}")
   @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.findById(id);
        return success(nursingProjectVo);
    }
// 1.4 修改护理项目
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }
// 1.5 删除护理项目信息
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目信息")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }

    // 1.6 启动或禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启动项目/禁用项目")
    public ResponseResult isEnable(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        nursingProjectService.isEnable(id,status);
        return success();
    }


    // 1.7 查询所有护理项目
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAll(){
        return success(nursingProjectService.selectAll());
    }

}
